/**
 * Created by liuzhen on 2017/2/27.
 */
define(["jquery","jqxcore","jqxdata","jqxbuttons","jqxscrollbar","jqxdropdownlist","jqxmenu","jqxpanel","jqxbuttongroup","jqxradiobutton","jquery_ui"],function () {
    var createGrid = function () {
        BJUI.init({
            JSPATH: '../lib/B-JUI/',         //[可选]框架路径
            PLUGINPATH: '../lib/B-JUI/plugins/', //[可选]插件路径
            loginInfo: {url: 'login_timeout.html', title: '登录', width: 440, height: 240}, // 会话超时后弹出登录对话框
            statusCode: {ok: 200, error: 300, timeout: 301}, //[可选]
            ajaxTimeout: 300000, //[可选]全局Ajax请求超时时间(毫秒)
            alertTimeout: 3000,  //[可选]信息提示[info/correct]自动关闭延时(毫秒)
            pageInfo: {
                total: 'totalRow',
                pageCurrent: 'pageCurrent',
                pageSize: 'pageSize',
                orderField: 'orderField',
                orderDirection: 'orderDirection'
            }, //[可选]分页参数
            keys: {statusCode: 'statusCode', message: 'message'}, //[可选]
            ui: {
                sidenavWidth: 220,
                showSlidebar: true, //[可选]左侧导航栏锁定/隐藏
                overwriteHomeTab: false //[可选]当打开一个未定义id的navtab时，是否可以覆盖主navtab(我的主页)
            },
            debug: true,    // [可选]调试模式 [true|false，默认false]
            theme: 'green' // 若有Cookie['bjui_theme'],优先选择Cookie['bjui_theme']。皮肤[五种皮肤:default, orange, purple, blue, red, green]

        })
        //时钟
        var today = new Date(), time = today.getTime()
        $('#bjui-date').html(today.formatDate('yyyy/MM/dd'))
        setInterval(function () {
            today = new Date(today.setSeconds(today.getSeconds() + 1))
            $('#bjui-clock').html(today.formatDate('HH:mm:ss'))
        }, 1000)

        require(["getGrid"],function(detail){
            //detail();
        });

    }
//菜单-事件-zTree
    function MainMenuClick(event, treeId, treeNode) {
        if (treeNode.target && treeNode.target == 'dialog' || treeNode.target == 'navtab')
            event.preventDefault()

        if (treeNode.isParent) {
            var zTree = $.fn.zTree.getZTreeObj(treeId)

            zTree.expandNode(treeNode)
            return
        }

        if (treeNode.target && treeNode.target == 'dialog')
            $(event.target).dialog({id:treeNode.targetid, url:treeNode.url, title:treeNode.name})
        else if (treeNode.target && treeNode.target == 'navtab')
            $(event.target).navtab({id:treeNode.targetid, url:treeNode.url, title:treeNode.name, fresh:treeNode.fresh, external:treeNode.external})
    }

// 满屏开关
    var bjui_index_container = 'container_fluid'

    function bjui_index_exchange() {
        bjui_index_container = bjui_index_container == 'container_fluid' ? 'container' : 'container_fluid'

        $('#bjui-top').find('> div').attr('class', bjui_index_container)
        $('#bjui-navbar').find('> div').attr('class', bjui_index_container)
        $('#bjui-body-box').find('> div').attr
    }

    function initEvent(){

    }
    function topNav(){
        $("#jqxMenu").jqxMenu({height: '48'});
        $("#jqxMenu").css('visibility', 'visible');
        $(".comboBox-type").jqxDropDownList({theme:"custom",width:100,placeHolder: "单据类型"});
        $(".comboBox-state").jqxDropDownList({theme:"custom",width:100,placeHolder: "单据状态"});
        $(".foot-toolbar-btnGroup").jqxButtonGroup({theme:"custom",mode: 'radio' });
        $(".defaultButton").jqxButton({theme:"custom" });

        $("#animation").on('change', function (event) {
            var value = event.args.checked;
            // enable or disable the menu's animation.
            if (!value) {
                $("#jqxMenu").jqxMenu({ animationShowDuration: 0, animationHideDuration: 0, animationShowDelay: 0 });
            }
            else {
                $("#jqxMenu").jqxMenu({ animationShowDuration: 300, animationHideDuration: 200, animationShowDelay: 200 });
            }
        });
        $("#disabled").on('change', function (event) {
            var value = event.args.checked;
            // enable or disable the menu
            if (!value) {
                $("#jqxMenu").jqxMenu({ disabled: false });
            }
            else {
                $("#jqxMenu").jqxMenu({ disabled: true });
            }
        });
        $("#hover").on('change', function (event) {
            var value = event.args.checked;
            // enable or disable the menu's hover effect.
            if (!value) {
                $("#jqxMenu").jqxMenu({ enableHover: false });
            }
            else {
                $("#jqxMenu").jqxMenu({ enableHover: true });
            }
        });
        $("#open").on('change', function (event) {
            var value = event.args.checked;
            // enable or disable the opening of the top level menu items when the user hovers them.
            if (!value) {
                $("#jqxMenu").jqxMenu({ autoOpen: false });
            }
            else {
                $("#jqxMenu").jqxMenu({ autoOpen: true });
            }
        });
        $("#topLevelArrows").on('change', function (event) {
            var value = event.args.checked;
            // enable or disable the opening of the top level menu items when the user hovers them.
            if (!value) {
                $("#jqxMenu").jqxMenu({ showTopLevelArrows: false });
            }
            else {
                $("#jqxMenu").jqxMenu({ showTopLevelArrows: true });
            }
        });

        require(["dialog"],function(app){
            //app.init();
        });
    }

    function tableEvent(){
        $(".defaultButton").jqxButton({theme:"custom",});
        //$("#popover").jqxPopover({offset: {left: -50, top:0}, arrowOffsetValue: 50, title: "Employeesssssss", showCloseButton: true, selector: $(".anniu") });

    }

    function init() {
        createGrid();
        initEvent();
        topNav();
        tableEvent();
    };
    return init();
});